package com.scuec.groupfive.entity;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import java.util.Date;

@Data
public class UserInfo {
    // 改为驼峰命名
    private Integer userId;         // 原 user_id
    private String username;
    private String password;
    private String email;
    private String phone;
    private String realName;        // 原 real_name
    private String gender;
    private String avatar;
    private String school;
    private String targetSchool;    // 原 target_school
    private Integer examYear;       // 原 exam_year
    private String role = "student";
    private Integer status;
    private Date lastLoginTime;     // 原 last_login_time

    // 添加数据库实际存在的字段
    @JsonProperty("createTime")
    private Date createdAt;         // 映射数据库 created_at

    @JsonProperty("updateTime")
    private Date updatedAt;         // 映射数据库 updated_at

    // 构造方法也需要同步修改字段名
    public UserInfo() {}

    public UserInfo(String username, String password, String email, String phone) {
        this.username = username;
        this.password = password;
        this.email = email;
        this.phone = phone;
        this.status = 1;
        this.role = "student";
    }

    public UserInfo(String username, String password, String email, String phone,
                    String realName, String gender, String avatar, String school,
                    String targetSchool, Integer examYear, String role) {
        this.username = username;
        this.password = password;
        this.email = email;
        this.phone = phone;
        this.realName = realName;        // 修改
        this.gender = gender;
        this.avatar = avatar;
        this.school = school;
        this.targetSchool = targetSchool; // 修改
        this.examYear = examYear;        // 修改
        this.role = role != null && (role.equals("admin") || role.equals("student"))
                ? role : "student";
        this.status = 1;
    }
}